import Layout from '@/layout'
import AdminDashboard from '@/views/admin/dashboard.vue'

export function getRoleRoutes(userType) {
  // 总公司路由（userType: 5）
  const adminRoutes = [
    {
      path: '/admin',
      component: Layout,
      redirect: '/admin/dashboard',
      name: 'Admin',
      meta: { title: '总公司管理', icon: 'el-icon-s-home', userType: [5] },
      children: [
        {
          path: 'dashboard',
          component: AdminDashboard,
          name: 'AdminDashboard',
          meta: { title: '首页', icon: 'el-icon-s-home', affix: true, userType: [5] }
        },
        {
          path: 'order-management',
          component: () => import('@/views/admin/order-management.vue'),
          name: 'OrderManagement',
          meta: { title: '订单管理', icon: 'el-icon-goods', userType: [5] }
        },
        {
          path: 'order-export',
          component: () => import('@/views/admin/order-export.vue'),
          name: 'OrderExport',
          meta: { title: '订单导出', icon: 'el-icon-download', userType: [5] }
        },
        {
          path: 'merchant-audit',
          component: () => import('@/views/admin/merchant-audit.vue'),
          name: 'MerchantAudit',
          meta: { title: '商家审核', icon: 'el-icon-share', userType: [5] }
        },
        {
          path: 'withdraw-audit',
          component: () => import('@/views/admin/withdraw-audit.vue'),
          name: 'WithdrawAudit',
          meta: { title: '提现审核', icon: 'el-icon-circle-check', userType: [5] }
        },
        {
          path: 'salesman-audit',
          component: () => import('@/views/admin/salesman-audit.vue'),
          name: 'SalesmanAudit',
          meta: { title: '业务员审核', icon: 'el-icon-circle-check', userType: [5] }
        },
        {
          path: 'add-salesman',
          component: () => import('@/views/admin/add-salesman.vue'),
          name: 'AddSalesman',
          meta: { title: '添加业务员', icon: 'el-icon-plus', userType: [5] }
        },
        {
          path: 'salesman-management',
          component: () => import('@/views/admin/salesman-management.vue'),
          name: 'SalesmanManagement',
          meta: { title: '业务员管理', icon: 'el-icon-user-solid', userType: [5] }
        },
        {
          path: 'merchant-management',
          component: () => import('@/views/admin/merchant-management.vue'),
          name: 'MerchantManagement',
          meta: { title: '商家管理', icon: 'el-icon-office-building', userType: [5] }
        },
        {
          path: 'region-agent-management',
          component: () => import('@/views/admin/region-agent-management.vue'),
          name: 'RegionAgentManagement',
          meta: { title: '区域代理管理', icon: 'el-icon-office-building', userType: [5] }
        },
        {
          path: 'proportion-config',
          component: () => import('@/views/admin/proportion-config.vue'),
          name: 'ProportionConfig',
          meta: { title: '分佣比例配置', icon: 'el-icon-coin', userType: [5] }
        },
        {
          path: 'region-contribution',
          component: () => import('@/views/admin/region-contribution.vue'),
          name: 'RegionContribution',
          meta: { title: '区域贡献值', icon: 'el-icon-s-data', userType: [5] }
        },
        {
          path: 'product-carousel',
          component: () => import('@/views/admin/product-carousel.vue'),
          name: 'ProductCarousel',
          meta: { title: '商品轮播管理', icon: 'el-icon-picture', userType: [5] }
        },
        {
          path: 'ad-config-management',
          component: () => import('@/views/admin/ad-config-management.vue'),
          name: 'AdConfigManagement',
          meta: { title: '广告配置', icon: 'el-icon-setting', userType: [5] }
        },
        {
          path: 'ad-income-log',
          component: () => import('@/views/admin/ad-income-log.vue'),
          name: 'AdIncomeLog',
          meta: { title: '广告收益日志', icon: 'el-icon-document', userType: [5] }
        },
        {
          path: 'account-management',
          component: () => import('@/views/admin/account-management.vue'),
          name: 'AccountManagement',
          meta: { title: '账户管理', icon: 'el-icon-money', userType: [5] }
        },
        {
          path: 'scheduled-task',
          component: () => import('@/views/admin/scheduled-task.vue'),
          name: 'ScheduledTask',
          meta: { title: '定时任务', icon: 'el-icon-timer', userType: [5] }
        },
        {
          path: 'profile',
          component: () => import('@/views/admin/profile.vue'),
          name: 'proFile',
          meta: { title: '个人中心', icon: 'el-icon-user', userType: [5] }
        },
        {
          path: 'merchant-detail',
          component: () => import('@/views/admin/merchant-detail.vue'),
          name: 'MerchantDetail',
          hidden: true,
          meta: { title: '商家详情', icon: 'el-icon-office-building', userType: [5] }
        }
      ]
    }
  ]

  // 区域代理路由（userType: 4）
  const agentRoutes = [
    {
      path: '/agent',
      component: Layout,
      redirect: '/agent/dashboard',
      name: 'Agent',
      meta: { title: '区域代理管理', icon: 'el-icon-s-home', userType: [4] },
      children: [
        {
          path: 'dashboard',
          component: () => import('@/views/agent/dashboard.vue'),
          name: 'AgentDashboard',
          meta: { title: '首页', icon: 'el-icon-s-home', affix: true, userType: [4] }
        },
        {
          path: 'merchant-management',
          component: () => import('@/views/agent/merchant-management.vue'),
          name: 'AgentMerchantManagement',
          meta: { title: '商家管理', icon: 'el-icon-share', userType: [4] }
        },
        {
          path: 'salesman-management',
          component: () => import('@/views/agent/salesman-management.vue'),
          name: 'AgentSalesmanManagement',
          meta: { title: '业务员管理', icon: 'el-icon-user', userType: [4] }
        },
        {
          path: 'order-management',
          component: () => import('@/views/agent/order-management.vue'),
          name: 'AgentOrderManagement',
          meta: { title: '订单管理', icon: 'el-icon-goods', userType: [4] }
        },
        {
          path: 'withdraw',
          component: () => import('@/views/agent/withdraw.vue'),
          name: 'AgentWithdraw',
          meta: { title: '提现管理', icon: 'el-icon-money', userType: [4] }
        },
        {
          path: 'bank-card',
          component: () => import('@/views/agent/bank-card.vue'),
          name: 'AgentBankCard',
          meta: { title: '银行卡管理', icon: 'el-icon-bank-card', userType: [4] }
        },
        {
          path: 'profile',
          component: () => import('@/views/aggregation/profile.vue'),
          name: 'AgentProfile',
          meta: { title: '个人中心', icon: 'el-icon-user', userType: [4] }
        },
        {
          path: 'income-detail',
          component: () => import('@/views/aggregation/income-detail.vue'),
          name: 'AgentIncomeDetail',
          hidden: true,
          meta: { title: '收益详情', icon: 'el-icon-money', userType: [4] }
        },
        {
          path: 'merchant-detail',
          component: () => import('@/views/admin/merchant-detail.vue'),
          name: 'AgentMerchantDetail',
          hidden: true,
          meta: { title: '商家详情', icon: 'el-icon-office-building', userType: [4] }
        }
      ]
    }
  ]

  // 业务员路由（userType: 2）
  const salesmanRoutes = [
    {
      path: '/salesman',
      component: Layout,
      redirect: '/salesman/dashboard',
      name: 'Salesman',
      meta: { title: '业务员管理', icon: 'el-icon-s-home', userType: [2] },
      children: [
        {
          path: 'dashboard',
          component: () => import('@/views/salesman/dashboard.vue'),
          name: 'SalesmanDashboard',
          meta: { title: '首页', icon: 'el-icon-s-home', affix: true, userType: [2] }
        },
        {
          path: 'merchant-management',
          component: () => import('@/views/salesman/merchant-management.vue'),
          name: 'SalesmanMerchantManagement',
          meta: { title: '商家管理', icon: 'el-icon-share', userType: [2] }
        },
        {
          path: 'bind-merchant',
          component: () => import('@/views/salesman/bind-merchant.vue'),
          name: 'BindMerchant',
          meta: { title: '绑定商家', icon: 'el-icon-plus', userType: [2] }
        },
        {
          path: 'withdraw',
          component: () => import('@/views/salesman/withdraw.vue'),
          name: 'SalesmanWithdraw',
          meta: { title: '提现管理', icon: 'el-icon-money', userType: [2] }
        },
        {
          path: 'bank-card',
          component: () => import('@/views/salesman/bank-card.vue'),
          name: 'SalesmanBankCard',
          meta: { title: '银行卡管理', icon: 'el-icon-bank-card', userType: [2] }
        },
        {
          path: 'profile',
          component: () => import('@/views/aggregation/profile.vue'),
          name: 'SalesmanProfile',
          meta: { title: '个人中心', icon: 'el-icon-user', userType: [2] }
        },
        {
          path: 'income-detail',
          component: () => import('@/views/aggregation/income-detail.vue'),
          name: 'SalesmanIncomeDetail',
          hidden: true,
          meta: { title: '收益详情', icon: 'el-icon-money', userType: [2] }
        }
      ]
    }
  ]

  // 商家路由（userType: 3）
  const merchantRoutes = [
    {
      path: '/merchant',
      component: Layout,
      redirect: '/merchant/dashboard',
      name: 'Merchant',
      meta: { title: '商家管理', icon: 'el-icon-s-home', userType: [3] },
      children: [
        {
          path: 'dashboard',
          component: () => import('@/views/merchant/dashboard.vue'),
          name: 'MerchantDashboard',
          meta: { title: '首页', icon: 'el-icon-s-home', affix: true, userType: [3] }
        },
        {
          path: 'product-management',
          component: () => import('@/views/merchant/product-management.vue'),
          name: 'ProductManagement',
          meta: { title: '商品管理', icon: 'el-icon-goods', userType: [3] }
        },
        {
          path: 'order-management',
          component: () => import('@/views/merchant/order-management.vue'),
          name: 'MerchantOrderManagement',
          meta: { title: '订单管理', icon: 'el-icon-tickets', userType: [3] }
        },
        {
          path: 'withdraw',
          component: () => import('@/views/merchant/withdraw.vue'),
          name: 'MerchantWithdraw',
          meta: { title: '提现管理', icon: 'el-icon-money', userType: [3] }
        },
        {
          path: 'bank-card',
          component: () => import('@/views/merchant/bank-card.vue'),
          name: 'MerchantBankCard',
          meta: { title: '银行卡管理', icon: 'el-icon-bank-card', userType: [3] }
        },
        {
          path: 'commission-detail',
          component: () => import('@/views/merchant/commission-detail.vue'),
          name: 'CommissionDetail',
          meta: { title: '积分明细', icon: 'el-icon-money', userType: [3] }
        },
        {
          path: 'merchant-info',
          component: () => import('@/views/merchant/merchant-info.vue'),
          name: 'MerchantInfo',
          meta: { title: '商户信息', icon: 'el-icon-edit', userType: [3] }
        },
        {
          path: 'user-count',
          component: () => import('@/views/merchant/user-count.vue'),
          name: 'UserCount',
          meta: { title: '用户数量', icon: 'el-icon-user', userType: [3] }
        },
        {
          path: 'task-management',
          component: () => import('@/views/admin/task-management.vue'),
          name: 'MerchantTaskManagement',
          meta: { title: '任务管理', icon: 'el-icon-tickets', userType: [3] }
        },
        {
          path: 'profile',
          component: () => import('@/views/aggregation/profile.vue'),
          name: 'MerchantProfile',
          meta: { title: '个人中心', icon: 'el-icon-user', userType: [3] }
        },
        {
          path: 'income-detail',
          component: () => import('@/views/aggregation/income-detail.vue'),
          name: 'MerchantIncomeDetail',
          hidden: true,
          meta: { title: '收益详情', icon: 'el-icon-money', userType: [3] }
        }
      ]
    }
  ]

  // 根据用户类型返回对应的路由
  switch (userType) {
    case 5: return adminRoutes      // 总公司
    case 4: return agentRoutes      // 区域代理
    case 2: return salesmanRoutes   // 业务员
    case 3: return merchantRoutes   // 商家
    default: return []              // 其他类型返回空数组
  }
}
